import { stringToDate } from "@/generic/Utils";
import { Icon, Tag, Input, Checkbox, Button, Select } from 'antd';
import { DIR_OBJECT, FILE_OBJECT, PATH_SEPARATOR } from "@/generic/ConfigParams";

// #### NEW_FIELDS #### | 自定义的字段 or 修改原先的字段
export const NEW_FIELDS = [
    { name: 'name', handle: (source) => source.orgPath.split(PATH_SEPARATOR).pop() },
    { 
        name: 'orgPath', 
        handle: (source) => source.orgPath.split(PATH_SEPARATOR).slice(0, -1).join(PATH_SEPARATOR)
    },
]

// #### TABLE_COLS ####
export const TABLE_COLS = [
    {
        dataIndex: 'name', text: "名称", width: '35%',
        render: (name, record) => (
            <>
                <a href="#" onClick={() => {}} style={{ cursor: "pointer", display: "contents" }}>
                    <Icon theme={DIR_OBJECT.theme}
                        style={{ color: (record.isDir ? DIR_OBJECT.color : FILE_OBJECT.color) }}
                        type={(record.isDir ? DIR_OBJECT.icon : FILE_OBJECT.icon)} />
                    <span style={{ marginLeft: "3px" }}>{name}</span>
                </a>
            </>
        ),
        // toDetail: { type: 'manager/updateCurrentPage', payload: { mark: 'detail' } },
    },
    {
        dataIndex: 'removeAt', text: "删除时间", width: '',
        render: (date, _) => <span>{stringToDate(date)}</span>,
    },
    {
        dataIndex: 'orgPath', text: "原始位置", width: '45%', isHidden: true,
        render: (orgPath, record) => (
            <>
                <span style={{ display: "contents" }}>: {orgPath || '\\'}</span>
                <span style={{ float: "left" }}>
                    <Tag 
                        color={record.diskID == "pub" ? "volcano" : "blue"} 
                        style={{marginRight: '4px'}}
                    >{record.diskID}</Tag>
                </span>
            </>
        ),
    },
]

// #### HEADER_OPTS ####
export const HEADER_OPTS = {
    left: [
        {
            isGroup: false,
            className: 'headerBtns',
            args: { icon: 'rest', type: 'danger', },
            confirm: {
                name: '文件',
                action: { type: 'fileManage/methodAdapter', method: 'delete', payload: {empty: true} },
            },
            msgTip: '清空',
        },
        {
            isGroup: false,
            className: 'headerBtns',
            args: { icon: 'reload', type: 'primary', },
            confirm: {
                name: '文件',
                action: { type: 'fileManage/methodAdapter', method: 'update', payload: { restore: true } },
            },
            msgTip: '还原',
        },
        {
            className: 'headerBtns', isHidden: true,
            text: '删除',
            args: { icon: 'delete', type: 'danger', ghost: true },
            confirm: {
                name: '文件',
                action: { type: 'fileManage/methodAdapter', method: 'delete', payload: {} },
            },
            msgTip: '删除',
        },
        {
            className: 'headerBtns', isHidden: true,
            text: '还原',
            args: { icon: 'redo', type: 'primary', ghost: true },
            action: { type: 'fileManage/methodAdapter', method: 'update', payload: {} },
            msgTip: '还原',
        },
    ],
    right: {
        onSearch: () => { },
    },
}